***************************************
*ANALYSIS
***************************************
*set directory to the folder containing data files
cd "C:\Users\treis\Dropbox\Dem Breakdown\CPS\New folder"

log using demanalysis, replace
use "breakdown cases.dta", clear
xtset ccode year

*FN2. "autocratization episodes overlap with only 7 percent of all downward annual moves on V-DEM’s electoral democracy index"

gen vdemdown=0
replace vdemdown=1 if v2x_polyarchy<l.v2x_polyarchy&l.v2x_polyarchy~=.
replace vdemdown=. if l.v2x_polyarchy==.|v2x_polyarchy==.
tab autocratization vdemdown, column

*Figure 1
*Panels A and B

twoway line mvdemdem year if country_name=="France"&year>1899, graphregion(color(white)) title("A. All V-DEM democracies, electoral or liberal", size(medium) position(6) margin(t=5)) ysize(4) xtitle("") ytitle("") xlabel(1900(20)2020, labsize(small)) ylabel(0(.1).6, labsize(small))
graph save vdemdem, replace
twoway line mvdemlib year if country_name=="France"&year>1899, graphregion(color(white)) title("B. V-DEM liberal democracies", size(medium) position(6) margin(t=5)) ysize(4) xtitle("") ytitle("") xlabel(1900(20)2020, labsize(small)) ylabel(0(.1).6, labsize(small))
graph save vdemlib, replace
gr combine vdemdem.gph vdemlib.gph, graphregion(color(white)) note("", size(tiny)) col(2) ysize(4) imargin(r=10)
graph export Figure1A&B.png, replace

*Panels C,D,E

twoway line mfhpolfree year if ccode==2&year>1969, graphregion(color(white) lw(medium)) title("C. Freedom House 'free' countries", size(medium) position(6) margin(t=8)) ysize(4) ytitle("") xtitle("") xlabel(1972(8)2020, labsize(medsmall)) ylabel(0(.1).5, labsize(medsmall))
graph save fhpolfree, replace
twoway line proplied6 year if ccode==2&year>1899, graphregion(color(white) lw(medium)) subtitle("D. Lexical Index 'electoral democracies'", size(medium) position(6) margin(t=5)) title("(Lexical index = 6)", size(medium) position(6)) ysize(4) xtitle("") ytitle("") xlabel(1900(20)2020, labsize(medsmall)) ylabel(0(.1).7, labsize(medsmall))
graph save proplied6, replace
twoway line mpol2more5 year if ccode==2, graphregion(color(white) lw(medium)) subtitle("E. Polity 'democracies'", size(medium) position(6) margin(t=5)) title("(Polity2 >= 6)", size(medium) position(6) ) ysize(4) xtitle("") ytitle("") xlabel(1820(40)2020, labsize(medsmall)) ylabel(0(.1).6, labsize(medsmall))
graph save pol2, replace
gr combine fhpolfree.gph proplied6.gph pol2.gph, graphregion(color(white) ) note("", size(tiny)) col(3) ysize(3)
graph export Figure1CD&E.png, replace

*However, there is a downward trend in the proportion of V-DEM liberal democracies (Figure 1.B). 
*From almost 24 percent of countries in 2010, these have fallen to 19 percent in 2021.
list year mvdemlib if year>2005&ccode==200, clean noobs

*Freedom House reports a similar drop in the proportion of “free” states from 47 percent in 2007 to 43 percent in 2021 
list year mfhpolfree if year>2005&ccode==200, clean noobs

*Which countries account for the declines in V-DEM liberal democracy and Freedom House “free” states? 
xtset ccode year
list country  if year==2021&fhpolfree==0&l14.fhpolfree==1
list country  if year==2021&vdemlib==0&l14.vdemlib==1
list country if year==2021&fhpolfree==0&l14.fhpolfree==1&vdemlib==0&l14.vdemlib==1

*Two of V-DEM’s backsliders actually rose slightly on Freedom House’s political rights measure, 
*while three of Freedom House’s backsliders increased on V-DEM’s liberalism index
xtset ccode year
list country l14.PR PR if year==2021&vdemlib==0&l14.vdemlib==1, clean noobs
list country l14.v2x_liberal v2x_liberal if year==2021&fhpolfree==0&l14.fhpolfree==1, clean noobs

*Only three of V-DEM’s 11 backsliders—Poland, Hungary, and Mauritius—were downgraded because of change in political institutions per se.
*The other eight—Ghana, South Africa, Portugal, Austria, Czechia, Lithuania, Slovenia, and Trinidad and Tobago fell below the threshold on one or two of three 
*legal indicators that V-DEM added to the formula in 2018: access to justice for men and for women and transparency of legal enforcement.
xtset ccode year
*List those downgraded that fell below one of the political thresholds
list country year v2elmulpar_osp v2elfrfair_osp v2x_polyarchy v2x_liberal if year==2021&vdemlib==0&l14.vdemlib==1&(v2elmulpar_osp<=2|v2elfrfair_osp<=2|v2x_polyarchy<=.5|v2x_liberal<=.8), clean noobs
*List those downgraded that fell below one of the legal thresholds
list country year v2cltrnslw_osp v2clacjstm_osp v2clacjstw_osp v2elmulpar_osp v2elfrfair_osp v2x_polyarchy v2x_liberal if year==2021&vdemlib==0&l14.vdemlib==1&(v2cltrnslw_osp<=3| v2clacjstm_osp<=3|v2clacjstw_osp<=3), clean noobs


*Explicitly political requirements for V-DEM liberal democracy: v2elmulpar_osp>2, v2elfrfair_osp>2, v2x_polyarchy>.5, v2x_liberal>.8.
*New legal requirements: v2cltrnslw_osp>3, v2clacjstm_osp>3, v2clacjstw_osp>3
sort country year
list country year v2elmulpar_osp v2elfrfair_osp v2x_polyarchy v2x_liberal v2cltrnslw_osp v2clacjstm_osp v2clacjstw_osp if year>2006&year~=.&(country=="Ghana"|country=="South Africa" |country=="Poland" |country=="Portugal" |country=="Austria" |country=="Czech Republic" |country=="Lithuania"|country=="Mauritius"|country=="Slovenia"|country=="Hungary"|country=="Trinidad and Tobago"), clean noobs
list country year if v2elmulpar_osp<=2 & year>2006&year~=.&(country=="Ghana"|country=="South Africa" |country=="Poland" |country=="Portugal" |country=="Austria" |country=="Czech Republic" |country=="Lithuania"|country=="Mauritius"|country=="Slovenia"|country=="Hungary"|country=="Trinidad and Tobago"), clean noobs
list country year if v2elfrfair_osp<=2 & year>2006&year~=.&(country=="Ghana"|country=="South Africa" |country=="Poland" |country=="Portugal" |country=="Austria" |country=="Czech Republic" |country=="Lithuania"|country=="Mauritius"|country=="Slovenia"|country=="Hungary"|country=="Trinidad and Tobago"), clean noobs
list country year if v2x_polyarchy<=0.5 & year>2006&year~=.&(country=="Ghana"|country=="South Africa" |country=="Poland" |country=="Portugal" |country=="Austria" |country=="Czech Republic" |country=="Lithuania"|country=="Mauritius"|country=="Slovenia"|country=="Hungary"|country=="Trinidad and Tobago"), clean noobs
list country year if v2x_liberal<=0.8 & year>2006&year~=.&(country=="Ghana"|country=="South Africa" |country=="Poland" |country=="Portugal" |country=="Austria" |country=="Czech Republic" |country=="Lithuania"|country=="Mauritius"|country=="Slovenia"|country=="Hungary"|country=="Trinidad and Tobago"), clean noobs
list country year if v2cltrnslw_osp<=3 & year>2006&year~=.&(country=="Ghana"|country=="South Africa" |country=="Poland" |country=="Portugal" |country=="Austria" |country=="Czech Republic" |country=="Lithuania"|country=="Mauritius"|country=="Slovenia"|country=="Hungary"|country=="Trinidad and Tobago"), clean noobs
list country year if v2clacjstm_osp<=3 & year>2006&year~=.&(country=="Ghana"|country=="South Africa" |country=="Poland" |country=="Portugal" |country=="Austria" |country=="Czech Republic" |country=="Lithuania"|country=="Mauritius"|country=="Slovenia"|country=="Hungary"|country=="Trinidad and Tobago"), clean noobs
list country year if v2clacjstw_osp<=3 & year>2006&year~=.&(country=="Ghana"|country=="South Africa" |country=="Poland" |country=="Portugal" |country=="Austria" |country=="Czech Republic" |country=="Lithuania"|country=="Mauritius"|country=="Slovenia"|country=="Hungary"|country=="Trinidad and Tobago"), clean noobs

*Indeed, out of the 26 breakdowns of liberal democracy that V-DEM’s indicator identifies since 1900, in only five cases did the country fall 
*below the relevant threshold on one of the political subcomponents (multiparty elections, free and fair elections, electoral democracy index, 
*liberalism index). All of these five cases came during or right after one of the world wars. In the other 21 cases, the downgrade follows from 
*deterioration on legal transparency or access to justice for men or for women. 
xtset ccode year
*List those downgraded that fell below one of the political thresholds
list country year v2elmulpar_osp v2elfrfair_osp v2x_polyarchy v2x_liberal if vdemlibbkd==1&(v2elmulpar_osp<=2|v2elfrfair_osp<=2|v2x_polyarchy<=.5|v2x_liberal<=.8), clean noobs
*List those downgraded that fell below one of the legal thresholds
list country year v2cltrnslw_osp v2clacjstm_osp v2clacjstw_osp v2elmulpar_osp v2elfrfair_osp v2x_polyarchy v2x_liberal if vdemlibbkd==1&(v2cltrnslw_osp<=3| v2clacjstm_osp<=3|v2clacjstw_osp<=3), clean noobs

*In four of the cases, the drop below the threshold was not statistically significant. That is, the 95% CI included points above the threshold (_codehigh was above the threshold).
*Explicitly political requirements for V-DEM liberal democarcy: v2elmulpar_osp>2, v2elfrfair_osp>2, v2x_polyarchy>.5, v2x_liberal>.8.
*New legal requirements: v2cltrnslw_osp>3, v2clacjstm_osp>3, v2clacjstw_osp>3
bys ccode (year): carryforward v2elmulpar_osp_codehigh v2elfrfair_osp_codehigh, replace
list country v2elmulpar_osp_codehigh v2elfrfair_osp_codehigh v2x_polyarchy_codehigh v2x_liberal_codehigh v2cltrnslw_osp_codehigh v2clacjstm_osp_codehigh v2clacjstw_osp_codehigh if year==2021&vdemlib==0&l14.vdemlib==1, clean noobs compress

*Figure 2
*Panels A, B
*Obtain data including confidence intervals for VDEM elec and lib dem indexes from VDEM's online graphing website: https://v-dem.net/data_analysis/VariableGraph/
import delimited "Elec dem.csv", clear
sort year
save "Elec dem.dta", replace
import delimited "Lib dem.csv", clear
sort year
merge year using "Elec dem.dta"
twoway (rarea electoraldemocracyindexcilow electoraldemocracyindexcihigh year if year>1899, subtitle("A. Average V-DEM electoral democracy", size(large) position(6) margin(t=5)) title("score worldwide", size(large) position(6) ) color(gs15) legend(off) graphregion(color(white) lw(thick)) ysize(4) xtitle("") ytitle("") xlabel(1900(20)2020, labsize(medsmall)) ylabel(0(.1).6, labsize(medsmall)))|| (line electoraldemocracyindex year if year>1899, lcolor(navy)) 
graph save elec, replace
twoway (rarea liberaldemocracyindexcilow liberaldemocracyindexcihigh year if year>1899, subtitle("B. Average VDEM liberal democracy", size(large) position(6) margin(t=5)) title("score worldwide", size(large) position(6) ) color(gs15) legend(off) graphregion(color(white) lw(thick)) ysize(4) xtitle("") ytitle("") xlabel(1900(20)2020, labsize(medsmall)) ylabel(0(.1).6, labsize(medsmall)))|| (line liberaldemocracyindex year if year>1899, lcolor(navy)) 
graph save lib, replace
gr combine  elec.gph lib.gph , graphregion(color(white)) note("", size(tiny)) col(2) ysize(3)
graph export Figure2.png, replace

*Both record a moderate deterioration of 5-6 percentage points. 
egen maxel = max(electoraldemocracyindex)
egen maxlib = max(liberaldemocracyindex)
gen elpctmax = electoraldemocracyindex/maxel
gen libpctmax = liberaldemocracyindex/maxlib
list elpctmax libpctmax if year==2021

*Appendix Figure A1: FH and Polity
use "breakdown cases.dta", clear
twoway line mpol2norm year if ccode==2&year<2019, graphregion(color(white)) subtitle("D. Average Polity2 score", size(large) position(6) margin(t=5)) title("(rescaled to 0-1)", size(large) position(6) ) ysize(4) xtitle("") ytitle("") xlabel(1820(40)2020, labsize(medsmall)) ylabel(0(.1).8, labsize(medsmall))
graph save pol2a, replace
twoway line mfhpolrn year if ccode==2&year>1969, graphregion(color(white)) subtitle("C. Average FH political liberties score", size(large) position(6) margin(t=5)) title("(rescaled to 0-1 and reversed)", size(large) position(6) ) ysize(4) ytitle("") xtitle("") xlabel(1972(8)2020, labsize(medsmall)) ylabel(.3(.1).7, labsize(medsmall))
graph save fhpolfreea, replace
gr combine  fhpolfreea.gph pol2a.gph , graphregion(color(white)) note("", size(tiny)) col(2) ysize(2)
graph export FigureA1.png, replace

egen maxmpol2 = max(mpol2norm) if ccode==2
egen maxmfhpol = max(mfhpolrn) if ccode==2
gen pol2pctmax = mpol2norm/maxmpol2
gen fhpctmax = mfhpolrn/maxmfhpol
list  fhpctmax if year==2021&ccode==2
list pol2pctmax  if year==2018&ccode==2


*Median of V-DEM democracy scores (see Little and Meng (2022))
bys year: egen medv2xpoly = median(v2x_polyarchy)
bys year: egen medv2xlib = median(v2x_libdem)
twoway line medv2xpoly medv2xlib year, graphregion(color(white))


*Figure 3
twoway (line mvdemdembkd year if ccode==2&year>1899&year<2022, graphregion(color(white)) legend(off)  lw(medthick) lpattern(shortdash) subtitle("A. Proportion of V-DEM democracies", size(medium) position(6) margin(t=5)) title("that broke down", size(medium) position(6)) ysize(2) xtitle("") ytitle("") xlabel(1900(20)2020, labsize(medsmall)) ylabel(0(.1).4, labsize(medsmall))) (line mvdemdembkdma year if ccode==2&year>1899&year<2022, lw(medthick) lcolor(dknavy))
graph save mvdemdembkd, replace
twoway (line mvdemlibbkd year if ccode==2&year>1899&year<2022, graphregion(color(white)) legend(off)  lw(medthick) lpattern(shortdash) subtitle("B. Proportion of V-DEM liberal democracies", size(medium) position(6) margin(t=5)) title("that became illiberal", size(medium) position(6)) ysize(2) xtitle("") ytitle("") xlabel(1900(20)2020, labsize(medsmall)) ylabel(0(.1).4, labsize(medsmall))) (line mvdemlibbkdma year if ccode==2&year>1899&year<2022, lw(medthick) lcolor(dknavy))
graph save mvdemlibbkd, replace
twoway (line mlbdsig  year if ccode==2&year>1899&year<2022, graphregion(color(white)) legend(off)  lw(medthick) lpattern(shortdash) subtitle("C. Proportion that became illiberal by a", size(medium) position(6) margin(t=5)) title("statistically significant amount", size(medium) position(6)) ysize(2) xtitle("") ytitle("") xlabel(1900(20)2020, labsize(medsmall)) ylabel(0(.1).4, labsize(medsmall))) (line mmlbdsigma year if ccode==2&year>1899&year<2022, lw(medthick) lcolor(dknavy))
graph save mlbdsig, replace
gr combine mvdemdembkd.gph mvdemlibbkd.gph mlbdsig.gph, graphregion(color(white)) note("Note: solid line is centered 5-year moving average.", size(small)) col(3) ysize(3)
graph export Figure3.png, replace


*Figure A2
twoway (line mpolbkd year if ccode==2&year>1899&year<2019, graphregion(color(white)) legend(off)  lw(medthick) subtitle("E. Proportion of Polity 'democracies'", size(vlarge) position(6) margin(t=5)) title("that broke down", size(vlarge) position(6)) ysize(3) xtitle("") ytitle("") xlabel(1900(20)2020, labsize(medlarge)) ylabel(0(.1).4, labsize(medlarge))) 
graph save mpolbkd, replace
twoway (line mfhpolbkd year if ccode==2&year>1972&year<2022, graphregion(color(white)) legend(off) lw(medthick)  subtitle("D. Proportion of FH 'free' states", size(vlarge) position(6) margin(t=5))  title("that became 'unfree'", size(vlarge) position(6)) ysize(3) xtitle("") ytitle("") xlabel(1972(8)2020, labsize(medlarge)) ylabel(0(.1).4, labsize(medlarge))) 
graph save mfhpolbkd.gph, replace
gr combine  mfhpolbkd.gph mpolbkd.gph, graphregion(color(white)) note("", size(tiny)) col(2) ysize(2)
graph export FigA2.png, replace

*Figure 4
*Panels A, B, C

bys year: egen hhh = mean(pol2norm) if pol2more5==1
bys year: egen mpol2normd = max(hhh) 
bys year: egen iii = mean(fhpolrn) if fhpolfree==1
bys year: egen mfhpolrnd = max(iii) 
bys year: egen jjj = mean(v2x_libdem) if vdemlib==1
bys year: egen mlibdemd = max(jjj) 
bys year: egen kkk = mean(v2x_polyarchy) if vdemel==1
bys year: egen meldemd = max(kkk) 
drop hhh iii jjj kkk

*Figure 4
twoway line meldemd year if ccode==2&year>1899, graphregion(color(white) lw(thick)) subtitle("A. Average V-DEM electoral democracy", size(medlarge)  position(6) margin(t=5)) title("score among electoral democracies", size(medlarge)  position(6)) ysize(3) xtitle("") ytitle("") xlabel(1900(20)2020, labsize(medium)) ylabel(0(.1)1, labsize(medium))
graph save vdeld, replace
twoway line mlibdemd year if ccode==2&year>1899, graphregion(color(white) lw(thick)) subtitle("B. Average V-DEM liberal democracy", size(medlarge)  position(6) margin(t=5)) title("score among liberal democracies", size(medlarge)  position(6)) ysize(3) xtitle("") ytitle("") xlabel(1900(20)2020, labsize(medium)) ylabel(0(.1)1, labsize(medium))
graph save vdlibd, replace
gr combine vdeld.gph vdlibd.gph , graphregion(color(white)) note("", size(tiny)) col(2) ysize(3)
graph export Figure4.png, replace



*There is a slight decline—by about 3 percentage points—in average quality among the V-DEM liberal democracies since 2010, but, 
*if anything, the quality trend is upward among the electoral democracies. 
xtset ccode year
list year mlibdemd meldemd if year>1980&ccode==2, clean noobs

*Figure A3
twoway line mpol2normd year if ccode==2&year<2019&year>1899, graphregion(color(white) lw(thick)) subtitle("B. Average Polity2 score among democracies", size(medlarge)  position(6) margin(t=5)) title("(rescaled to 0-1)", size(medlarge)  position(6)) ysize(4) xtitle("") ytitle("") xlabel(1900(20)2020, labsize(medium)) ylabel(0(.1)1, labsize(medium))
graph save pol2d, replace
twoway line mfhpolrnd year if ccode==2&year>1969, graphregion(color(white) lw(thick)) subtitle("A. Average FH political liberties score among", size(medlarge)   position(6) margin(t=5)) title("free countries (rescaled 0-1 and reversed)", size(medlarge)  position(6)) ysize(4) ytitle("") xtitle("") xlabel(1972(8)2020, labsize(medium)) ylabel(0(.1)1, labsize(medium))
graph save fhpold, replace
gr combine fhpold.gph pol2d.gph , graphregion(color(white)) note("", size(tiny)) col(2) ysize(3)
graph export FigureA3.png, replace



***********************************************
*CLAASSEN AJPS (2019)
***********************************************

*REPLICATING CLAASSEN'S REGRESSIONS

*CLAASSEN'S REGRESSION
use "breakdown cases.dta", clear
xtset ccode year
reg libdem_vd l.libdem_vd l2.libdem_vd supdem_m1 lngdp_imp_m1 gdp_imp_grth_m1 libdem_regun_m1 res_cp_wdi_di_m1 pr_muslim, rob

*SAME, INTERACTING DEMOCRACY SUPPORT WITH REGIME TYPE
gen lregime = l.regime_vd
reg libdem_vd l.libdem_vd l2.libdem_vd c.supdem_m1##i.lregime lngdp_imp_m1 gdp_imp_grth_m1 libdem_regun_m1 res_cp_wdi_di_m1 pr_muslim, rob
*TABLE 1 
*lregime: 1 = CLOSED AUTOCRACIES, 2 = ELECTORAL AUTOCRACIES, 3 = ELECTORAL DEMOCRACIES, 4 = LIBERAL DEMOCRACIES
margins, dydx(supdem_m1) at(lregime=(0(1)3))

*TABLE 2
use "breakdown cases.dta", clear
gen vvv=0
replace vvv=1 if v2x_regime==3&year==2009
bys ccode: egen lib2009=max(vvv)
bys year: egen www = mean(v2x_libdem) if lib2009==1
bys year: egen mlibdem = max(www)
drop www
bys year: egen www = mean(supdem_trim) if lib2009==1
bys year: egen mlibsupdem = max(www)
drop vvv www
xtset ccode year
gen dvdlib = v2x_libdem-l8.v2x_libdem
gen l8vdemlib = l8.vdemlib
gen d8mlibdem=mlibdem - l8.mlibdem
gen l8mlibsupdem = l8.mlibsupdem
gen l8supdemtrim =l8.supdem_trim
gen dsup=supdem_trim- l8.supdem_trim

*top libdem backsliders 2009-17
sort dvdlib
list country dvdlib if year==2017&l8vdemlib==1

list l8mlibsupdem mlibsupdem d8mlibdem if year==2017&ccode==2
list country l8supdemtrim supdem_trim dvdlib if year==2017&country=="Hungary"
list country l8supdemtrim supdem_trim dvdlib if year==2017&country=="Poland"
list country l8supdemtrim supdem_trim dvdlib if year==2017&ccode==2
list country l8supdemtrim supdem_trim dvdlib if year==2017&country=="Czech Republic"
list country l8supdemtrim supdem_trim dvdlib if year==2017&country=="Spain"

*There are exceptions such as Greece, where democratic support fell by .55, and South Africa, where it fell by .22. 
list country l8supdemtrim supdem_trim dsup dvdlib if year==2017&country=="Greece"
list country l8supdemtrim supdem_trim dsup dvdlib if year==2017&country=="South Africa"


*Among electoral democracies, both support for democracy and the quality of it were falling on average in 2009-17. 
*Average support dropped by .03 while the average liberal democracy score among countries that were electoral democracies in 2009 fell by .02. 

gen vvv=0
replace vvv=1 if v2x_regime==2&year==2009
bys ccode: egen el2009=max(vvv)
bys year: egen www = mean(v2x_libdem) if el2009==1
bys year: egen meldem = max(www)
drop www
bys year: egen www = mean(supdem_trim) if el2009==1
bys year: egen melsupdem = max(www)
drop vvv www
xtset ccode year
gen l8vdemel = l8.vdemel
gen d8meldem=meldem - l8.meldem

*top eldem backsliders 2009-17
sort dvdlib
list country dvdlib dsup if year==2017&l8vdemel==1
xtset ccode year
list l8.melsupdem melsupdem d8meldem if year==2017&ccode==2

*As the democracy scores of Turkey, Paraguay, Ukraine, and Bulgaria fell, support for democracy among their citizens rose. 
*In these countries, at least, backsliding cannot be attributed to popular disenchantment with democracy 
list country dvdlib dsup if year==2017&(country=="Turkey"|country=="Paraguay"|country=="Ukraine"|country=="Bulgaria")

corr v2x_libdem supdem_trim if country=="Poland"&year>2008&year<2019
corr v2x_libdem supdem_trim if country=="Hungary"&year>2008&year<2019
corr v2x_libdem supdem_trim if ccode==2&year>2008&year<2019
corr v2x_libdem supdem_trim if country=="Czech Republic"&year>2008&year<2019
corr v2x_libdem supdem_trim if country=="Spain"&year>2008&year<2019

corr v2x_libdem supdem_trim if country=="Turkey"&year>2008&year<2019
corr v2x_libdem supdem_trim if country=="Paraguay"&year>2008&year<2019
corr v2x_libdem supdem_trim if country=="Bulgaria"&year>2008&year<2019
corr v2x_libdem supdem_trim if country=="Ukraine"&year>2008&year<2019

*FIGUREs A4, A5

*FIGURE A4
twoway (line v2x_libdem year if country=="Hungary"&year>2008&year<2018, title("Hungary", size(medsmall)) subtitle(" ") yaxis(1) xlabel(2009(2)2017, labsize(vsmall)) yscale(axis(1)) legend(off) lcolor(navy gs4) graphregion(color(white)) ylabel(.3(.1).9, labsize(vsmall)) plotregion(lcolor(black)) ytitle("") legend(order(1 "Actual liberal democracy score, left scale" 2 "Popular support for democracy index, right scale")) legend(region(lstyle(none))  size(vsmall)) lpattern(solid shortdash)) (line supdem_trim year if country=="Hungary"&year>2008&year<2018, lpattern(shortdash) lcolor(red) yaxis(2) ylabel(-.3(.2)1, axis(2)  labsize(vsmall)) yscale(axis(2)) ytitle("", axis(2)) xtitle(" ") note("Correlation: r = -.97", size(vsmall)))
graph save Hungary, replace
twoway (line v2x_libdem year if country=="Poland"&year>2008&year<2018, title("Poland", size(medsmall)) subtitle(" ") yaxis(1) xlabel(2009(2)2017, labsize(vsmall)) yscale(axis(1)) legend(off) lcolor(navy gs4) graphregion(color(white)) ylabel(.3(.1).9, labsize(vsmall)) plotregion(lcolor(black)) ytitle("") legend(order(1 "Actual liberal democracy score, left scale" 2 "Popular support for democracy index, right scale")) legend(region(lstyle(none))  size(vsmall)) lpattern(solid shortdash)) (line supdem_trim year if country=="Poland"&year>2008&year<2018, lpattern(shortdash) lcolor(red) yaxis(2) ylabel(-.3(.2)1, axis(2)  labsize(vsmall)) yscale(axis(2)) ytitle("", axis(2)) xtitle(" ") note("Correlation: r = -.86", size(vsmall)))
graph save Poland, replace
twoway (line v2x_libdem year if ccode==2&year>2008&year<2018, title("USA", size(medsmall)) subtitle(" ") yaxis(1) xlabel(2009(2)2017, labsize(vsmall)) yscale(axis(1)) legend(off) lcolor(navy gs4) graphregion(color(white)) ylabel(.3(.1).9, labsize(vsmall)) plotregion(lcolor(black)) ytitle("") legend(order(1 "Actual liberal democracy score, left scale" 2 "Popular support for democracy index, right scale")) legend(region(lstyle(none))  size(vsmall)) lpattern(solid shortdash)) (line supdem_trim year if ccode==2&year>2008&year<2018, lpattern(shortdash) lcolor(red) yaxis(2) ylabel(-.3(.2)1, axis(2)  labsize(vsmall)) yscale(axis(2)) ytitle("", axis(2)) xtitle(" ") note("Correlation: r = -.82", size(vsmall)))
graph save USA, replace
twoway (line v2x_libdem year if country=="Czech Republic"&year>2008&year<2018, title("Czech Republic", size(medsmall)) subtitle(" ") yaxis(1) xlabel(2009(2)2017, labsize(vsmall)) yscale(axis(1)) legend(off) lcolor(navy gs4) graphregion(color(white)) ylabel(.3(.1).9, labsize(vsmall)) plotregion(lcolor(black)) ytitle("") legend(order(1 "Actual liberal democracy score, left scale" 2 "Popular support for democracy index, right scale")) legend(region(lstyle(none))  size(vsmall)) lpattern(solid shortdash)) (line supdem_trim year if country=="Czech Republic"&year>2008&year<2018, lpattern(shortdash) lcolor(red) yaxis(2) ylabel(-.3(.2)1, axis(2)  labsize(vsmall)) yscale(axis(2)) ytitle("", axis(2)) xtitle(" ") note("Correlation: r = .57", size(vsmall)))
graph save Czech, replace
twoway (line v2x_libdem year if country=="Spain"&year>2008&year<2018, title("Spain", size(medsmall)) subtitle(" ") yaxis(1) xlabel(2009(2)2017, labsize(vsmall)) yscale(axis(1)) legend(off) lcolor(navy gs4) graphregion(color(white)) ylabel(.3(.1).9, labsize(vsmall)) plotregion(lcolor(black)) ytitle("") legend(order(1 "Actual liberal democracy score, left scale" 2 "Popular support for democracy index, right scale")) legend(region(lstyle(none))  size(vsmall)) lpattern(solid shortdash)) (line supdem_trim year if country=="Spain"&year>2008&year<2018, lpattern(shortdash) lcolor(red) yaxis(2) ylabel(-.3(.2)1, axis(2)  labsize(vsmall)) yscale(axis(2)) ytitle("", axis(2)) xtitle(" ") note("Correlation: r = -.86", size(vsmall)))
graph save Spain, replace

gr combine  Hungary.gph Poland.gph USA.gph Czech.gph Spain.gph, graphregion(color(white)) note("", size(tiny)) col(2) ysize(8) 
graph export FigureA4.png, replace

*FIGURE A5
twoway (line v2x_libdem year if country=="Turkey"&year>2009&year<2018, title("Turkey", size(medsmall)) subtitle(" ") yaxis(1) xlabel(2010(2)2017, labsize(vsmall)) yscale(axis(1)) legend(off) lcolor(navy gs4) graphregion(color(white)) ylabel(.1(.1).7, labsize(vsmall)) plotregion(lcolor(black)) ytitle("") legend(order(1 "Actual liberal democracy score, left scale" 2 "Popular support for democracy index, right scale")) legend(region(lstyle(none))  size(vsmall)) lpattern(solid shortdash)) (line supdem_trim year if country=="Turkey"&year>2009&year<2018, lpattern(shortdash) lcolor(red) yaxis(2) ylabel(-1.3(.2).3, axis(2)  labsize(vsmall)) yscale(axis(2)) ytitle("", axis(2)) xtitle(" ") note("Correlation: r = .09", size(vsmall)))
graph save Turkey, replace
twoway (line v2x_libdem year if country=="Paraguay"&year>2009&year<2018, title("Paraguay", size(medsmall)) subtitle(" ") yaxis(1) xlabel(2010(2)2017, labsize(vsmall)) yscale(axis(1)) legend(off) lcolor(navy gs4) graphregion(color(white)) ylabel(.1(.1).7, labsize(vsmall)) plotregion(lcolor(black)) ytitle("") legend(order(1 "Actual liberal democracy score, left scale" 2 "Popular support for democracy index, right scale")) legend(region(lstyle(none))  size(vsmall)) lpattern(solid shortdash)) (line supdem_trim year if country=="Paraguay"&year>2009&year<2018, lpattern(shortdash) lcolor(red) yaxis(2) ylabel(-1.3(.2).3, axis(2)  labsize(vsmall)) yscale(axis(2)) ytitle("", axis(2)) xtitle(" ") note("Correlation: r = -.34", size(vsmall)))
graph save Paraguay, replace
twoway (line v2x_libdem year if country=="Bulgaria"&year>2009&year<2018, title("Bulgaria", size(medsmall)) subtitle(" ") yaxis(1) xlabel(2010(2)2017, labsize(vsmall)) yscale(axis(1)) legend(off) lcolor(navy gs4) graphregion(color(white)) ylabel(.1(.1).7, labsize(vsmall)) plotregion(lcolor(black)) ytitle("") legend(order(1 "Actual liberal democracy score, left scale" 2 "Popular support for democracy index, right scale")) legend(region(lstyle(none))  size(vsmall)) lpattern(solid shortdash)) (line supdem_trim year if country=="Bulgaria"&year>2009&year<2018, lpattern(shortdash) lcolor(red) yaxis(2) ylabel(-1.3(.2).3, axis(2)  labsize(vsmall)) yscale(axis(2)) ytitle("", axis(2)) xtitle(" ") note("Correlation: r = -.71", size(vsmall)))
graph save Bulgaria, replace
twoway (line v2x_libdem year if country=="Ukraine"&year>2009&year<2018, title("Ukraine", size(medsmall)) subtitle(" ") yaxis(1) xlabel(2010(2)2017, labsize(vsmall)) yscale(axis(1)) legend(off) lcolor(navy gs4) graphregion(color(white)) ylabel(.1(.1).7, labsize(vsmall)) plotregion(lcolor(black)) ytitle("") legend(order(1 "Actual liberal democracy score, left scale" 2 "Popular support for democracy index, right scale")) legend(region(lstyle(none))  size(vsmall)) lpattern(solid shortdash)) (line supdem_trim year if country=="Ukraine"&year>2009&year<2018, lpattern(shortdash) lcolor(red) yaxis(2) ylabel(-1.3(.2).3, axis(2)  labsize(vsmall)) yscale(axis(2)) ytitle("", axis(2)) xtitle(" ") note("Correlation: r = -.93", size(vsmall)))
graph save Ukraine, replace

gr combine Turkey.gph Paraguay.gph Bulgaria.gph Ukraine.gph, graphregion(color(white)) note("", size(tiny)) col(2) ysize(8) 
graph export FigureA5.png, replace


*********************************************************************************
*MAINWARING AND PEREZ-LINAN
*********************************************************************************
use "linanwork.dta", clear
*Table A4
eststo clear
*replicating the Mainwaring-Perez-Linan "main model" of breakdowns Model 4.4.5
gllamm break  npr_all rad_gov rad_opp region us_t d_nonla gdp_1_ ghist10 oilmin indust_ age age2 age3 shugart multip s_1 if (break !=. & year>1944 & year<2006), link(logit) fam(binom) i(cc_cow) robust trace nolog
eststo
*same excluding Argentina and Uruguay
gllamm break  npr_all rad_gov rad_opp region us_t d_nonla gdp_1_ ghist10 oilmin indust_ age age2 age3 shugart multip s_1 if (break !=. & year>1944 & year<2006 & cc_cow~=160 & cc_cow~=165), link(logit) fam(binom) i(cc_cow) robust trace nolog
eststo

esttab est1 est2  using "tableMPL.doc", replace nocons se star(* 0.05 ** 0.01) mtitles( "Replicating model 4.4.5" "Excluding Argentina and Uruguay")  b(a2) rtf sca(ll chi2 p)


************************
*Explaining breakdowns
************************

*In addition, v2cacamps turns out to correlate hardly at all with two survey-based measures of affective polarization that are 
*available for a (very) limited number of country-years (Ward and Tavits 2019, Boxell, Gentzkow, and Shapiro 2020). 
*There are also large, non-random gaps in the VDEM data. And when data do exist, some of the classifications are puzzling; 
*for instance, the US in 2020 was rated as more polarized than Rwanda in 1994, Iran in 1979, Germany in 1932, and Spain in 1935! 
*Another V-DEM variable, “polarization of society” (v2smpolsoc), was only available from 2000.
use "breakdown cases.dta", clear
xtset ccode year
cor v2cacamps_ord affective_polarization_sd
cor v2cacamps_ord partisan_affect_polarization

list country year v2cacamps if (ccode==2&year==2020)|(country=="Rwanda"&year==1994)|(country=="Iran"&year==1979)|(country=="Germany"&year==1932)|(country=="Spain"&year==1935)
tab year v2smpolsoc

*State capacity ...the estimates of Hanson and Sigman (2013)... correlates very highly (r = .78) with income per capita
corr Capacity lngdppcf


*Table 3
*VDEM Electoral Democracy
use "vdemsur.dta", clear
eststo clear
xtset ccode year
stset vdemdemyrs, id(demid) failure(vdemdembkd==1)
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds lprespipedpi lmadgrowthf lpostcoldw lneighvdem2 ldmvdemdembkd lgrowdifvdem, dis(wei)  cluster(spellno)  
eststo
*eststo1
*keeping just vars that sig at at least p < .10
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds lmadgrowthf ldmvdemdembkd, dis(wei)  cluster(spellno)
eststo
*eststo2
predict vdemhat, hazard
twoway line vdemhat year if ccode==2&year>1899, graphregion(color(white) lw(medthick)) subtitle("Predicted hazard of US becoming", size(medium) position(6) margin(t=5)) title("non democracy (VDEM)", size(medium) position(6)) ysize(4) ytitle("") xtitle("") xlabel(1900(20)2020, labsize(medium)) ylabel(0(.04).16, labsize(medium))
graph save vdemhat, replace
list country year vdemhat if (ccode==2&year>2015)|(ccode==255&year==1933)|(ccode==155&year==1973)

*with oil, state capacity, inequality
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds lmadgrowthf ldmvdemdembkd lavginimkt lCapacity llnoil, dis(wei)  cluster(spellno)  
eststo  
*eststo3

*with polarization
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds lmadgrowthf ldmvdemdembkd lv2cacamps, dis(wei)  cluster(spellno)  
eststo
*eststo4

*VDEM Liberal Democracy
use "vlibsur.dta", clear
stset vdemlibyrs, id(demid) failure(vdemlibbkd==1)
streg llngdppcf lv2x_libdem lv2cltrnslw lsumvdemlib lnlpastvlibbds lprespipedpi lmadgrowthf lpostcoldw lneighvdem2l ldmvdemlibbkd lgrowdifvdem, dis(wei)  cluster(spellno)
eststo
*eststo5
streg llngdppcf lv2cltrnslw lsumvdemlib lmadgrowthf lgrowdifvdem, dis(wei)  cluster(spellno)
eststo
*eststo6
predict vlibhat, hazard
twoway line vlibhat year if ccode==2&year>1969, graphregion(color(white) lw(medthick)) subtitle("Predicted hazard of US becoming", size(medium) position(6) margin(t=5)) title("non liberal democracy (VDEM)", size(medium) position(6)) ysize(4) ytitle("") xtitle("") xlabel(1970(10)2020, labsize(medium)) ylabel(0(.04).16, labsize(medium))
graph save vlibhat, replace
*list country year vlibhat if (ccode==2&year>2015)|(ccode==255&year==1932)|(ccode==155&year==1972)
*list year vlibhat llngdppcf lv2cltrnslw lmadgrowthf lgrowdifvdem if ccode==2

*with oil, state capacity, inequality
streg llngdppcf lv2cltrnslw lsumvdemlib lmadgrowthf lgrowdifvdem lavginimkt lCapacity llnoil, dis(wei)  cluster(spellno) iter(1000)  
eststo
*eststo7

*with polarization
streg llngdppcf lv2cltrnslw lsumvdemlib lmadgrowthf lgrowdifvdem lv2cacamps, dis(wei)  cluster(spellno)  
eststo
*eststo8

*Table 3
esttab est1 est2 est3 est4 est5 est6 est7 est8 using "table3.doc", replace nocons se star(* 0.10 ** 0.05 *** 0.01) mtitles("V-DEM democracy" "V-DEM democracy" "V-DEM democracy" "V-DEM democracy" "V-DEM liberal democracy" "V-DEM liberal democracy" "V-DEM liberal democracy" "V-DEM liberal democracy")  b(a2) rtf sca(ll chi2 p) eform

*Oil and gas revenues had no effect, which is not so surprising given that the largest hydrocarbon producers per capita 
*among the V-DEM democracies in recent years were Norway, Trinidad and Tobago, and Canada.
use "breakdown cases.dta", clear
gsort -oil_gas_valuepop_2014 
list country oil_gas_valuepop_2014 if year==2014&vdemdem==1, clean noobs

*Despite much discussion of polarization in the West, most breakdowns of liberal democracies have occurred in countries at low levels of polarization according to V-DEM. 
*Only 24 percent of these took place in countries that the previous year had been polarized to a “noticeable” or “large” extent.
use "vlibsur.dta", clear
xtset ccode year
gen lv2camps_ord = l.v2cacamps_ord
tab lv2camps_ord vdemlibbkd, col
*Even for electoral democracies, only 52 percent of the breakdowns occurred in countries that 
*were politically polarized to a “noticeable” or “large” extent.
use "vdemsur.dta", clear
xtset ccode year
gen lv2camps_ord = l.v2cacamps_ord
tab lv2camps_ord vdemdembkd, col

*TABLE A3, Figure A3: FH, Polity, LIED
eststo clear
*Polity2
use "pol6sur.dta", clear
stset demyrs, id(demid) failure(polbkd==1)
streg llngdppcf lpolity2 llnsumdem lnlpastpolbds lprespipedpi madgrowthf lpostcoldw lneighpol2 ldmpolbkd lgrowdifpol, dis(wei) cluster(spellno) 
eststo
*eststo1
predict pol6hat, hazard
twoway line pol6hat year if ccode==2, graphregion(color(white) lw(thick)) subtitle("A. Predicted hazard of US falling", size(medium) position(6) margin(t=5)) title("below Polity2 = 6, model 1", size(medium) position(6))ysize(4) xtitle("") ytitle("") xlabel(1800(40)2020, labsize(medium)) ylabel(0(.04).08, labsize(medium))
graph save pol6hat, replace
list country year pol6hat if (ccode==2&year>2015)|(ccode==255&year==1932)|(ccode==155&year==1972)
*with oil etc.
streg llngdppcf lpolity2 llnsumdem lnlpastpolbds  lprespipedpi madgrowthf lpostcoldw lneighpol2 ldmpolbkd lgrowdifpol lavginimkt lCapacity llnoil, dis(wei) cluster(spellno) 
eststo
*eststo 2
*with polarization
streg llngdppcf lpolity2 llnsumdem lnlpastpolbds  lprespipedpi madgrowthf lpostcoldw lneighpol2 ldmpolbkd lgrowdifpol lpolfact, dis(wei) cluster(spellno) 
eststo
*eststo 3

*Freedom House
use "fhsur.dta", clear
xtset ccode year
stset fhfyrs, id(demid) failure(fhpolbkd==1)
streg llngdppcf lfhpolnr llnsumvdem lnlpastfhfbds lprespipedpi madgrowthf lpostcoldw lneighfhpol ldmfhpolbkd lgrowdiffhf if year>1969, dis(wei)  cluster(spellno)  
eststo
*eststo4
predict fhfhat, hazard
twoway line fhfhat year if ccode==2&year>1969, graphregion(color(white) lw(thick)) subtitle("B. Predicted hazard of US becoming", size(medium) position(6) margin(t=5)) title("un-free (FH), model 4", size(medium) position(6)) ysize(4) ytitle("") xtitle("") xlabel(1970(10)2020, labsize(medium)) ylabel(0(.04).08, labsize(medium))
graph save fhfhat, replace
*with oil etc.
streg llngdppcf lfhpolnr llnsumvdem lnlpastfhfbds lprespipedpi madgrowthf lpostcoldw lneighfhpol ldmfhpolbkd lgrowdiffhf lavginimkt lCapacity llnoil  if year>1969, dis(wei)  cluster(spellno)  
eststo
*eststo5
*with polarization
streg llngdppcf lfhpolnr llnsumvdem lnlpastfhfbds lprespipedpi madgrowthf lpostcoldw lneighfhpol ldmfhpolbkd lgrowdiffhf lv2cacamps  if year>1969, dis(wei)  cluster(spellno)  
eststo
*eststo6

*LIED
*Note: does not converge if use ln of liedyrs, so just use liedyrs (lagged).
use "liedsur.dta", clear
stset liedyrs, id(demid) failure(liedbkd)
streg llngdppcf  llnsumliedyrs lnlpastliedbkds lprespipedpi madgrowthf lpostcoldw lneighlied ldmliedbkd lgrowdiflied, dis(wei)  cluster(spellno) iter(1000)
eststo
*eststo7
predict liedhat, hazard
twoway line liedhat year if ccode==2, graphregion(color(white) lw(thick)) subtitle("C. Predicted hazard of US falling", size(medium) position(6) margin(t=5)) title("below LIED = 6, model 7", size(medium) position(6))ysize(4) xtitle("") ytitle("") xlabel(1960(10)2020, labsize(medium)) ylabel(0(.04).08, labsize(medium))
graph save liedhat, replace
list country year liedhat if (ccode==2&year>2015)|(ccode==255&year==1932)|(ccode==155&year==1972)
*with oil etc.
streg llngdppcf  llnsumliedyrs lnlpastliedbkds lprespipedpi madgrowthf lpostcoldw lneighlied ldmliedbkd lgrowdiflied lavginimkt lCapacity llnoil, dis(wei)  cluster(spellno) 
eststo
*eststo8
*predict liedhat1, hazard
*twoway line liedhat1 year if ccode==2, graphregion(color(white)) subtitle("H. Predicted hazard of US falling", size(small) position(6) margin(t=5)) title("below LIED = 6, model 8", size(small) position(6))ysize(4) xtitle("") ytitle("") xlabel(1960(10)2020, labsize(vsmall)) ylabel(0(.04).08, labsize(vsmall))
*graph save liedhat1, replace
*polarization
streg llngdppcf  llnsumliedyrs lnlpastliedbkds lprespipedpi madgrowthf lpostcoldw lneighlied ldmliedbkd lgrowdiflied lv2cacamps, dis(wei)  cluster(spellno) 
eststo
*eststo9
*predict liedhat2, hazard
*twoway line liedhat2 year if ccode==2, graphregion(color(white)) subtitle("I. Predicted hazard of US falling", size(small) position(6) margin(t=5)) title("below LIED = 6, model 9", size(small) position(6))ysize(4) xtitle("") ytitle("") xlabel(1960(10)2020, labsize(vsmall)) ylabel(0(.04).08, labsize(vsmall))
*graph save liedhat2, replace

*Table A3
esttab est1 est2 est3 est4 est5 est6 est7 est8 est9 using "tableA3.doc", replace nocons se star(* 0.10 ** 0.05 *** 0.01) mtitles("Polity2" "Polity2" "Polity2" "FH 'free'" "FH 'free'" "FH 'free'" "Lexical index" "Lexical index" "Lexical index")  b(a2) rtf sca(ll chi2 p) eform


*Replacing pre-tax gini with post-tax gini
eststo clear
*VDEM Electoral Democracy
use "vdemsur.dta", clear
xtset ccode year
stset vdemdemyrs, id(demid) failure(vdemdembkd==1)
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds madgrowthf lavginidisp lCapacity llnoil, dis(wei)  cluster(spellno)  
eststo

*VDEM Liberal Democracy
use "vlibsur.dta", clear
xtset ccode year
stset vdemlibyrs, id(demid) failure(vdemlibbkd==1)
streg llngdppcf lv2cltrnslw llibwrse  madgrowthf  lgrowdifvdem lavginidisp lCapacity llnoil, dis(wei)  cluster(spellno) iter(1000)  
eststo
esttab est1 est2  using "tabledisp.doc", replace nocons se star(* 0.10 ** 0.05 *** 0.01) mtitles("V-DEM democracy" "V-DEM liberal democracy")  b(a2) rtf sca(ll chi2 p) eform


*Beger et al. "In addition, the “substantial” changes often immediately reverse themselves, sometimes fully disappearing within a few years."
*Associational – Core Civil Society Index - v2xcs_ccsi. Substantial downward change is -.05. 

use "V-Dem-CY-Full+Others-v12.dta", clear
xtset country_id year
*Associational
gen assdown = 0
replace assdown = 1 if v2xcs_ccsi<=l.v2xcs_ccsi-.05
replace assdown = . if v2xcs_ccsi==.|l.v2xcs_ccsi==.
gen d5ass = f5.v2xcs_ccsi-v2xcs_ccsi
gsort d5ass
*list country_name year d5ass if assdown==1, clean noobs
gen d5ass1234 = .
replace d5ass1234=1 if d5ass<0
replace d5ass1234=2 if d5ass==0
replace d5ass1234=3 if d5ass>0&d5ass~=.
replace d5ass1234=4 if d5ass>=0.05&d5ass~=.
tab d5ass1234 if assdown==1
*So 35.5% at least partially reverse within 5 years and 24% have completely recovered the .05 within 5 years.

*Electoral – Vertical Accountability Index - v2x_veracc_osp
use "V-Dem-CY-Full+Others-v12.dta", clear
xtset country_id year
gen vadown = 0
replace vadown = 1 if v2x_veracc_osp<=l.v2x_veracc_osp-.05
replace vadown = . if v2x_veracc_osp==.|l.v2x_veracc_osp==.
gen d5va = f5.v2x_veracc_osp-v2x_veracc_osp
gsort d5va
gen d5va1234 = .
replace d5va1234=1 if d5va<0
replace d5va1234=2 if d5va==0
replace d5va1234=3 if d5va>0&d5va~=.
replace d5va1234=4 if d5va>=0.05&d5va~=.
tab d5va1234 if vadown==1
*So about 58% at least partially reverse within 5 years and 39% have completely recovered the .05 within 5 years.


*AUTOCRATIZATION EPISODES

*Autocratization episodes
*Table A4
eststo clear
use "llautsur.dta", clear
xtset ccode year
stset llautyrsd, id(demid) failure(autfirst==1)
streg llngdppcf lv2x_libdem lv2xcivlib llnsumvdem lnlpastauts lprespipedpi lmadgrowthf lpostcoldw lneighvdem2 ldmvdemaut lgrowdifvdem, dis(wei)  cluster(spellno)  
eststo
*eststo1
*trimmed model
streg llngdppcf lv2x_libdem lv2xcivlib llnsumvdem lnlpastauts lmadgrowthf lgrowdifvdem, dis(wei)  cluster(spellno)
eststo
*eststo2
predict authat, hazard
twoway line authat year if ccode==2, graphregion(color(white)) subtitle("D. Predicted hazard of US beginning an autocratization episode", size(medium) position(6) margin(t=5)) title("(Table A4, model 2)", size(medium) position(6)) ysize(4) xtitle("") ytitle("") xlabel(1920(10)2020, labsize(medium)) ylabel(0(.04).16, labsize(medium))
graph save authat, replace
list country year authat if (ccode==2&year>2015)|(ccode==255&year==1932)|(ccode==155&year==1972)
*with oil, etc.
streg llngdppcf lv2x_libdem lv2xcivlib llnsumvdem lnlpastauts lmadgrowthf lgrowdifvdem lavginimkt lCapacity llnoil, dis(wei) cluster(spellno) 
eststo
*eststo 3
*polarization
streg llngdppcf lv2x_libdem lv2xcivlib llnsumvdem lnlpastauts lmadgrowthf lgrowdifvdem lv2cacamps , dis(wei) cluster(spellno) 
eststo
*eststo 4

esttab est1 est2 est3 est4 using "TableA4.doc", replace nocons se star(* 0.10 ** 0.05 *** 0.01)  b(a2) rtf sca(ll chi2 p) eform


*EVALUATING FORECASTS
*Forecasting 1 year forward for 14 years. Using model with just the sig vars. 
*Electoral Democracy
*For Table A5
*Each bloc provides one line in table. Any breakdown countries listed at bottom with rank in hazard list. The other statistics also printed out.
use "vdemsur.dta", clear
stset vdemdemyrs, id(demid) failure(vdemdembkd==1)
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds ldmvdemdembkd lmadgrowthf if year<2006, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
roctab vdemdembkd vdemhat if year==2006
prtab vdemdembkd vdemhat if year==2006, inter nograph
roctab vdemdembkd vdemhat if year>=2006
prtab vdemdembkd vdemhat if year>=2006, inter nograph
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2006&vdemdembkd==1, clean noobs

use "vdemsur.dta", clear
stset vdemdemyrs, id(demid) failure(vdemdembkd==1)
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds ldmvdemdembkd lmadgrowthf if year<2007, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
roctab vdemdembkd vdemhat if year==2007
prtab vdemdembkd vdemhat if year==2007, inter nograph
roctab vdemdembkd vdemhat if year>=2007
prtab vdemdembkd vdemhat if year>=2007, inter nograph
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2007&vdemdembkd==1, clean noobs

use "vdemsur.dta", clear
stset vdemdemyrs, id(demid) failure(vdemdembkd==1)
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds ldmvdemdembkd lmadgrowthf if year<2008, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
*roctab vdemdembkd vdemhat if year==2008
*prtab vdemdembkd vdemhat if year==2008, inter nograph
*cannot calculate these since no breakdowns this year
roctab vdemdembkd vdemhat if year>=2008
prtab vdemdembkd vdemhat if year>=2008, inter nograph
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2008&vdemdembkd==1, clean noobs

use "vdemsur.dta", clear
stset vdemdemyrs, id(demid) failure(vdemdembkd==1)
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds ldmvdemdembkd lmadgrowthf if year<2009, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
roctab vdemdembkd vdemhat if year==2009
prtab vdemdembkd vdemhat if year==2009, inter nograph
roctab vdemdembkd vdemhat if year>=2009
prtab vdemdembkd vdemhat if year>=2009, inter nograph
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2009&vdemdembkd==1, clean noobs

use "vdemsur.dta", clear
stset vdemdemyrs, id(demid) failure(vdemdembkd==1)
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds ldmvdemdembkd lmadgrowthf if year<2010, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
roctab vdemdembkd vdemhat if year==2010
prtab vdemdembkd vdemhat if year==2010, inter nograph
roctab vdemdembkd vdemhat if year>=2010
prtab vdemdembkd vdemhat if year>=2010, inter nograph
drop x
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2010&vdemdembkd==1, clean noobs

use "vdemsur.dta", clear
stset vdemdemyrs, id(demid) failure(vdemdembkd==1)
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds ldmvdemdembkd lmadgrowthf if year<2011, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
roctab vdemdembkd vdemhat if year==2011
prtab vdemdembkd vdemhat if year==2011, inter nograph
roctab vdemdembkd vdemhat if year>=2011
prtab vdemdembkd vdemhat if year>=2011, inter nograph
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2011&vdemdembkd==1, clean noobs

use "vdemsur.dta", clear
stset vdemdemyrs, id(demid) failure(vdemdembkd==1)
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds ldmvdemdembkd lmadgrowthf if year<2012, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
roctab vdemdembkd vdemhat if year==2012
prtab vdemdembkd vdemhat if year==2012, inter nograph
roctab vdemdembkd vdemhat if year>=2012
prtab vdemdembkd vdemhat if year>=2012, inter nograph
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2012&vdemdembkd==1, clean noobs

use "vdemsur.dta", clear
stset vdemdemyrs, id(demid) failure(vdemdembkd==1)
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds ldmvdemdembkd lmadgrowthf if year<2013, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
roctab vdemdembkd vdemhat if year==2013
prtab vdemdembkd vdemhat if year==2013, inter nograph
roctab vdemdembkd vdemhat if year>=2013
prtab vdemdembkd vdemhat if year>=2013, inter nograph
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2013&vdemdembkd==1, clean noobs

use "vdemsur.dta", clear
stset vdemdemyrs, id(demid) failure(vdemdembkd==1)
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds ldmvdemdembkd lmadgrowthf if year<2014, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
roctab vdemdembkd vdemhat if year==2014
prtab vdemdembkd vdemhat if year==2014, inter nograph
roctab vdemdembkd vdemhat if year>=2014
prtab vdemdembkd vdemhat if year>=2014, inter nograph
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2014&vdemdembkd==1, clean noobs

use "vdemsur.dta", clear
stset vdemdemyrs, id(demid) failure(vdemdembkd==1)
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds ldmvdemdembkd lmadgrowthf if year<2015, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
roctab vdemdembkd vdemhat if year==2015
prtab vdemdembkd vdemhat if year==2015, inter nograph
roctab vdemdembkd vdemhat if year>=2015
prtab vdemdembkd vdemhat if year>=2015, inter nograph
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2015&vdemdembkd==1, clean noobs

use "vdemsur.dta", clear
stset vdemdemyrs, id(demid) failure(vdemdembkd==1)
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds ldmvdemdembkd lmadgrowthf if year<2016, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
*roctab vdemdembkd vdemhat if year==2016
*prtab vdemdembkd vdemhat if year==2016, inter nograph
*cannot calculate these since no breakdowns this year
roctab vdemdembkd vdemhat if year>=2016
prtab vdemdembkd vdemhat if year>=2016, inter nograph
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2016&vdemdembkd==1, clean noobs

use "vdemsur.dta", clear
stset vdemdemyrs, id(demid) failure(vdemdembkd==1)
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds ldmvdemdembkd lmadgrowthf if year<2017, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
roctab vdemdembkd vdemhat if year==2017
prtab vdemdembkd vdemhat if year==2017, inter nograph
roctab vdemdembkd vdemhat if year>=2017
prtab vdemdembkd vdemhat if year>=2017, inter nograph
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2017&vdemdembkd==1, clean noobs

use "vdemsur.dta", clear
stset vdemdemyrs, id(demid) failure(vdemdembkd==1)
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds ldmvdemdembkd lmadgrowthf if year<2018, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
roctab vdemdembkd vdemhat if year==2018
prtab vdemdembkd vdemhat if year==2018, inter nograph
roctab vdemdembkd vdemhat if year>=2018
prtab vdemdembkd vdemhat if year>=2018, inter nograph
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2018&vdemdembkd==1, clean noobs

use "vdemsur.dta", clear
stset vdemdemyrs, id(demid) failure(vdemdembkd==1)
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds ldmvdemdembkd lmadgrowthf if year<2019, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
roctab vdemdembkd vdemhat if year==2019
prtab vdemdembkd vdemhat if year==2019, inter nograph
roctab vdemdembkd vdemhat if year>=2019
prtab vdemdembkd vdemhat if year>=2019, inter nograph
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2019&vdemdembkd==1, clean noobs



*VDEM Liberal Democracy
*For Table A6
eststo clear
use "vlibsur.dta", clear
xtset ccode year
stset vdemlibyrs, id(demid) failure(vdemlibbkd==1)
streg llngdppcf lv2cltrnslw lsumvdemlib lmadgrowthf lgrowdifvdem  if year<2006, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
*roctab vdemlibbkd vdemhat if year==2006
*prtab vdemlibbkd vdemhat if year==2006, inter nograph
*cannot calculate these since no breakdowns this year
roctab vdemlibbkd vdemhat if year>=2006
prtab vdemlibbkd vdemhat if year>=2006, inter nograph
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2006&vdemlibbkd==1, clean noobs

use "vlibsur.dta", clear
xtset ccode year
stset vdemlibyrs, id(demid) failure(vdemlibbkd==1)
streg llngdppcf lv2cltrnslw lsumvdemlib lmadgrowthf lgrowdifvdem  if year<2007, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
*roctab vdemlibbkd vdemhat if year==2007
*prtab vdemlibbkd vdemhat if year==2007, inter nograph
*cannot calculate these since no breakdowns this year
roctab vdemlibbkd vdemhat if year>=2007
prtab vdemlibbkd vdemhat if year>=2007, inter nograph
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2007&vdemlibbkd==1, clean noobs

use "vlibsur.dta", clear
xtset ccode year
stset vdemlibyrs, id(demid) failure(vdemlibbkd==1)
streg llngdppcf lv2cltrnslw lsumvdemlib lmadgrowthf lgrowdifvdem  if year<2008, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
*roctab vdemlibbkd vdemhat if year==2008
*prtab vdemlibbkd vdemhat if year==2008, inter nograph
*cannot calculate these since no breakdowns this year
roctab vdemlibbkd vdemhat if year>=2008
prtab vdemlibbkd vdemhat if year>=2008, inter nograph
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2008&vdemlibbkd==1, clean noobs

use "vlibsur.dta", clear
xtset ccode year
stset vdemlibyrs, id(demid) failure(vdemlibbkd==1)
streg llngdppcf lv2cltrnslw lsumvdemlib lmadgrowthf lgrowdifvdem  if year<2009, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
*roctab vdemlibbkd vdemhat if year==2009
*prtab vdemlibbkd vdemhat if year==2009, inter nograph
*cannot calculate these since no breakdowns this year
roctab vdemlibbkd vdemhat if year>=2009
prtab vdemlibbkd vdemhat if year>=2009, inter nograph
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2009&vdemlibbkd==1, clean noobs

use "vlibsur.dta", clear
xtset ccode year
stset vdemlibyrs, id(demid) failure(vdemlibbkd==1)
streg llngdppcf lv2cltrnslw lsumvdemlib lmadgrowthf lgrowdifvdem if year<2010, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
roctab vdemlibbkd vdemhat if year==2010
prtab vdemlibbkd vdemhat if year==2010, inter nograph
roctab vdemlibbkd vdemhat if year>=2010
prtab vdemlibbkd vdemhat if year>=2010, inter nograph
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2010&vdemlibbkd==1, clean noobs

use "vlibsur.dta", clear
xtset ccode year
stset vdemlibyrs, id(demid) failure(vdemlibbkd==1)
streg llngdppcf lv2cltrnslw lsumvdemlib lmadgrowthf lgrowdifvdem  if year<2011, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
*roctab vdemlibbkd vdemhat if year==2011
*prtab vdemlibbkd vdemhat if year==2011, inter nograph
*cannot calculate these since no breakdowns this year
roctab vdemlibbkd vdemhat if year>=2011
prtab vdemlibbkd vdemhat if year>=2011, inter nograph
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2011&vdemlibbkd==1, clean noobs

use "vlibsur.dta", clear
xtset ccode year
stset vdemlibyrs, id(demid) failure(vdemlibbkd==1)
streg llngdppcf lv2cltrnslw lsumvdemlib lmadgrowthf lgrowdifvdem  if year<2012, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
*roctab vdemlibbkd vdemhat if year==2012
*prtab vdemlibbkd vdemhat if year==2012, inter nograph
*cannot calculate these since no breakdowns this year
roctab vdemlibbkd vdemhat if year>=2012
prtab vdemlibbkd vdemhat if year>=2012, inter nograph
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2012&vdemlibbkd==1, clean noobs

use "vlibsur.dta", clear
xtset ccode year
stset vdemlibyrs, id(demid) failure(vdemlibbkd==1)
streg llngdppcf lv2cltrnslw lsumvdemlib lmadgrowthf lgrowdifvdem  if year<2013, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
roctab vdemlibbkd vdemhat if year==2013
prtab vdemlibbkd vdemhat if year==2013, inter nograph
roctab vdemlibbkd vdemhat if year>=2013
prtab vdemlibbkd vdemhat if year>=2013, inter nograph
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2013&vdemlibbkd==1, clean noobs

use "vlibsur.dta", clear
xtset ccode year
stset vdemlibyrs, id(demid) failure(vdemlibbkd==1)
streg llngdppcf lv2cltrnslw lsumvdemlib lmadgrowthf lgrowdifvdem  if year<2014, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
*roctab vdemlibbkd vdemhat if year==2014
*prtab vdemlibbkd vdemhat if year==2014, inter nograph
*cannot calculate these since no breakdowns this year
roctab vdemlibbkd vdemhat if year>=2014
prtab vdemlibbkd vdemhat if year>=2014, inter nograph
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2014&vdemlibbkd==1, clean noobs

use "vlibsur.dta", clear
xtset ccode year
stset vdemlibyrs, id(demid) failure(vdemlibbkd==1)
streg llngdppcf lv2cltrnslw lsumvdemlib lmadgrowthf lgrowdifvdem  if year<2015, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
roctab vdemlibbkd vdemhat if year==2015
prtab vdemlibbkd vdemhat if year==2015, inter nograph
roctab vdemlibbkd vdemhat if year>=2015
prtab vdemlibbkd vdemhat if year>=2015, inter nograph
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2015&vdemlibbkd==1, clean noobs

use "vlibsur.dta", clear
xtset ccode year
stset vdemlibyrs, id(demid) failure(vdemlibbkd==1)
streg llngdppcf lv2cltrnslw lsumvdemlib lmadgrowthf lgrowdifvdem  if year<2016, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
roctab vdemlibbkd vdemhat if year==2016
prtab vdemlibbkd vdemhat if year==2016, inter nograph
roctab vdemlibbkd vdemhat if year>=2016
prtab vdemlibbkd vdemhat if year>=2016, inter nograph
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2016&vdemlibbkd==1, clean noobs

use "vlibsur.dta", clear
xtset ccode year
stset vdemlibyrs, id(demid) failure(vdemlibbkd==1)
streg llngdppcf lv2cltrnslw lsumvdemlib lmadgrowthf lgrowdifvdem  if year<2017, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
roctab vdemlibbkd vdemhat if year==2017
prtab vdemlibbkd vdemhat if year==2017, inter nograph
roctab vdemlibbkd vdemhat if year>=2017
prtab vdemlibbkd vdemhat if year>=2017, inter nograph
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2017&vdemlibbkd==1, clean noobs

use "vlibsur.dta", clear
xtset ccode year
stset vdemlibyrs, id(demid) failure(vdemlibbkd==1)
streg llngdppcf lv2cltrnslw lsumvdemlib lmadgrowthf lgrowdifvdem  if year<2018, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
roctab vdemlibbkd vdemhat if year==2018
prtab vdemlibbkd vdemhat if year==2018, inter nograph
roctab vdemlibbkd vdemhat if year>=2018
prtab vdemlibbkd vdemhat if year>=2018, inter nograph
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2018&vdemlibbkd==1, clean noobs

use "vlibsur.dta", clear
xtset ccode year
stset vdemlibyrs, id(demid) failure(vdemlibbkd==1)
streg llngdppcf lv2cltrnslw lsumvdemlib lmadgrowthf lgrowdifvdem  if year<2019, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
roctab vdemlibbkd vdemhat if year==2019
prtab vdemlibbkd vdemhat if year==2019, inter nograph
roctab vdemlibbkd vdemhat if year>=2019
prtab vdemlibbkd vdemhat if year>=2019, inter nograph
bys year: egen rhaz = rank(-vdemhat)
list country rhaz vdemhat if year==2019&vdemlibbkd==1, clean noobs


*Moreover, in 2 of the 3 “breakdowns” that the model failed to predict (Latvia in 2013 and in 2016), V-DEM downrated the country in one year 
*only to restore it to “liberal democracy” the next year, both times based on a temporary dip in “legal transparency.”
use "breakdown cases.dta", clear
list year v2x_regime v2cltrnslw_osp if country=="Latvia"&year>2009, clean noobs

*Median income among V-DEM “democracies” peaked in 1980 around $17,900 (at 2011 prices). It fell to under $10,000 in 1994, 
*and had recovered to around $17,100 in 2019 (using the Maddison data).
use "breakdown cases.dta", clear
gen vdemgdp = vdemdem*madgdppcf
replace vdemgdp=. if vdemgdp==0
bys year: egen medvdemgdp = median(vdemgdp)
list year medvdemgdp if year>1960&ccode==2, clean noobs

*Meanwhile, the number of democracies less than 10 years old surged from just six in 1977 to 39 in 1996, before falling back to 12 in 2021.  

use "breakdown cases.dta", clear
gen vdemdemunder10 = 0
replace vdemdemunder10=1 if vdemdem==1&vdemdemyrs<10
bys year: egen numunder10 = sum (vdemdemunder10)
list year numunder10 if year>1960&ccode==2, clean noobs


*SIMULATING FOR TABLE 4

*Just income and lv2x_libdem

*VDEM Electoral Democracy

*1.	Just Ln GDP per capita (t - 1)
use "vdemsur.dta", clear
eststo clear
xtset ccode year
stset vdemdemyrs, id(demid) failure(vdemdembkd==1)
streg llngdppcf if year<2000, dis(wei)  cluster(spellno)  
predict vdemsim, hazard
roctab vdemdembkd vdemsim if year>1999&year<2020
prtab vdemdembkd vdemsim if year>1999&year<2020, inter nograph
replace vdemsim=. if vdemdem~=1
bys year: egen sumhaz = sum(vdemsim)
bys year: egen sumbkd = sum(vdemdembkd)
replace sumhaz=. if year<2000
replace sumbkd=. if year<2000
sort ccode year
bys ccode: gen sumsumhaz = sum(sumhaz)
sort ccode year
bys ccode: gen sumsumbkd = sum(sumbkd)
sort ccode year
list year sumhaz sumbkd sumsumhaz sumsumbkd if year>1999&year<2020&ccode==2, clean noobs


*2.	Ln GDP per capita (t - 1), V-DEM liberal democracy index (t - 1)
use "vdemsur.dta", clear
xtset ccode year
stset vdemdemyrs, id(demid) failure(vdemdembkd==1)
streg llngdppcf lv2x_libdem if year<2000, dis(wei)  cluster(spellno)  
predict vdemsim, hazard
roctab vdemdembkd vdemsim if year>1999&year<2020
prtab vdemdembkd vdemsim if year>1999&year<2020, inter nograph
replace vdemsim=. if vdemdem~=1
bys year: egen sumhaz = sum(vdemsim)
bys year: egen sumbkd = sum(vdemdembkd)
replace sumhaz=. if year<2000
replace sumbkd=. if year<2000
sort ccode year
bys ccode: gen sumsumhaz = sum(sumhaz)
sort ccode year
bys ccode: gen sumsumbkd = sum(sumbkd)
sort ccode year
list year sumhaz sumbkd sumsumhaz sumsumbkd if year>1999&year<2020&ccode==2, clean noobs


*3.	Ln GDP per capita (t - 1), V-DEM liberal democracy index (t - 1), both fixed at 2000 level in subsequent years
use "vdemsur.dta", clear
xtset ccode year
gen llngdppcf00 = llngdppcf
replace llngdppcf00 = . if year>2000
bys ccode: carryforward llngdppcf00 if year>1999, replace
gen lv2x_libdem00 = lv2x_libdem
replace lv2x_libdem00 = . if year>2000
bys ccode: carryforward lv2x_libdem00  if year>1999, replace
stset vdemdemyrs, id(demid) failure(vdemdembkd==1)
streg llngdppcf00 lv2x_libdem00 if year<2000, dis(wei)  cluster(spellno)  
predict vdemsim, hazard
roctab vdemdembkd vdemsim if year>1999&year<2020
prtab vdemdembkd vdemsim if year>1999&year<2020, inter nograph
replace vdemsim=. if vdemdem~=1
bys year: egen sumhaz = sum(vdemsim)
bys year: egen sumbkd = sum(vdemdembkd)
replace sumhaz=. if year<2000
replace sumbkd=. if year<2000
sort ccode year
bys ccode: gen sumsumhaz = sum(sumhaz)
sort ccode year
bys ccode: gen sumsumbkd = sum(sumbkd)
sort ccode year
list year sumhaz sumbkd sumsumhaz sumsumbkd if year>1999&year<2020&ccode==2, clean noobs


*Figure 5
gr combine  vdemhat.gph vlibhat.gph, graphregion(color(white)) note("", size(tiny)) col(2) ysize(3)
graph export Figure5.png, replace

*But then the hazard falls, reaching an all-time low of .0003 in 2015. It rose a little after that but was still just .002 in 2020. 
*The estimated probability of the US falling from liberal to electoral democracy hit its all-time low of .0005, in 1996. 
*It rose slightly in the late 2000s, reaching 1 percent in 2011 as the global financial crisis depressed the US economy at a time when 
*autocracies were beating democracies in the global growth race. As of 2020, it had fallen back to .003.

use "vdemsur.dta", clear
xtset ccode year
stset vdemdemyrs, id(demid) failure(vdemdembkd==1)
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds lmadgrowthf ldmvdemdembkd, dis(wei)  cluster(spellno)
predict vdemhat, hazard
list country year vdemhat if (ccode==2&year>1899)

use "vlibsur.dta", clear
stset vdemlibyrs, id(demid) failure(vdemlibbkd==1)
streg llngdppcf lv2cltrnslw lsumvdemlib lmadgrowthf lgrowdifvdem, dis(wei)  cluster(spellno)
predict vlibhat, hazard
list country year vlibhat if (ccode==2&year>1899)

*Figure A6
gr combine  pol6hat.gph  fhfhat.gph  liedhat.gph , graphregion(color(white)) note("", size(tiny)) col(3) ysize(3)
graph export FigureA6.png, replace

*Autocratization episodes
eststo clear
use "llautsur.dta", clear
xtset ccode year
stset llautyrsd, id(demid) failure(autfirst==1)
streg llngdppcf lv2x_libdem lv2xcivlib llnsumvdem lnlpastauts lmadgrowthf lgrowdifvdem, dis(wei)  cluster(spellno)
predict authat, hazard
twoway line authat year if ccode==2, graphregion(color(white)) subtitle("D. Predicted hazard of US beginning an autocratization episode", size(medium) position(6) margin(t=5)) title("(Table A4, model 2)", size(medium) position(6)) ysize(4) xtitle("") ytitle("") xlabel(1920(10)2020, labsize(medium)) ylabel(0(.04).16, labsize(medium))
graph export FigureA6d.png, replace


*Using predictions from Table 2, model 4, including V-DEM’s polarization measure, the predicted hazard for the US in 2020 rises from .002 to .006.
use "vdemsur.dta", clear
stset vdemdemyrs, id(demid) failure(vdemdembkd==1)
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds lmadgrowthf ldmvdemdembkd lv2cacamps, dis(wei)  cluster(spellno)  
predict vdpolhat, hazard
list country year vdpolhat if (ccode==2&year>1899)


*For instance, using the V-DEM democracy model, Germany in 1933 was 35 times more likely to become undemocratic than was the US in 2020. 

use "vdemsur.dta", clear
stset vdemdemyrs, id(demid) failure(vdemdembkd==1)
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds ldmvdemdembkd lmadgrowthf, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
list country year vdemhat if (ccode==2&year==2020)|(country=="Germany"&year==1933)

*Chile in 1973 was eight times more likely. 
list country year vdemhat if (ccode==2&year==2020)|(country=="Chile"&year==1973)

*Even in a model including V-DEM’s polarization measure (Table 2, model 4), Germany in 1933 is 33 times 
*more likely than the US in 2020, and Chile in 1973 is 9 times more likely.
use "vdemsur.dta", clear
stset vdemdemyrs, id(demid) failure(vdemdembkd==1)
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds ldmvdemdembkd lmadgrowthf lv2cacamps, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
list country year vdemhat if (ccode==2&year==2020)|(country=="Germany"&year==1933)|(country=="Chile"&year==1973)


*Only one democracy has ever failed with a hazard lower than that of the US in 2020—Suriname, 
*which dipped into authoritarianism for one year in 1991, before snapping back to democracy. 
use "vdemsur.dta", clear
stset vdemdemyrs, id(demid) failure(vdemdembkd==1)
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds ldmvdemdembkd lmadgrowthf, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
gsort -vdemhat
list country year vdemhat if (ccode==2&year==2020)|vdemdembkd==1
xtset ccode year
list year vdemdem if country=="Suriname"&year>1985

*The US is sometimes compared to Hungary, which V-DEM downgraded to “electoral autocracy” 
*in 2010. Hungary’s hazard that year was 29 times that of the US in 2020. 

use "vlibsur.dta", clear
xtset ccode year
stset vdemlibyrs, id(demid) failure(vdemlibbkd==1)
streg llngdppcf lv2cltrnslw lsumvdemlib lmadgrowthf lgrowdifvdem, dis(wei)  cluster(spellno)
predict vlibhat, hazard
xtset ccode year
list country year l.v2x_regime v2x_regime vlibhat if (ccode==2&year==2020)|(country=="Hungary"&year==2010)

*No liberal democracy has been downgraded to electoral democracy with a hazard as low as that of the US in 2020. 
*The closest comparator is Chile in 2019; it had returned to liberal democracy by 2021. 
gsort -vlibhat
list country year vlibhat if (ccode==2&year==2020)|vdemlibbkd==1
list year vdemlib if country=="Chile"&year>2015

*Using predictions from Table 2, model 4, including V-DEM’s polarization measure, the predicted hazard for the US in 2020 is .006.
use "vdemsur.dta", clear
stset vdemdemyrs, id(demid) failure(vdemdembkd==1)
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds ldmvdemdembkd lmadgrowthf lv2cacamps, dis(wei)  cluster(spellno)  
predict vdemhat, hazard
list country year vdemhat if (ccode==2&year==2020)

*Another way to put this is to estimate how severe an economic crisis would have to be to raise the odds of democratic breakdown for the US 
*to the level of, say, Chile in 1973. The answer is that it would take a collapse of GDP per capita in a single year of about 22 percent.  

use "vdemsur.dta", clear
xtset ccode year
stset vdemdemyrs, id(demid) failure(vdemdembkd==1)
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds ldmvdemdembkd lmadgrowthf, dis(wei) cluster(spellno)
predict vdemhat, hazard
list country year vdemhat if (ccode==2&year==2020)|(ccode==155&year==1973)

*so hazard for Chile in 1973 was .0181. Need to raise the hazard for US to .0181.
replace lmadgrowthf=-21 if ccode==2&year==2020
drop vdemhat
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds ldmvdemdembkd lmadgrowthf, dis(wei)  cluster(spellno)
predict vdemhat, hazard
list vdemhat if year==2020&ccode==2

replace lmadgrowthf=-22 if ccode==2&year==2020
drop vdemhat
streg llngdppcf lv2x_polyarchy lv2x_libdem llnsumvdem lnlpastvdembds ldmvdemdembkd lmadgrowthf, dis(wei)  cluster(spellno)
predict vdemhat, hazard
list vdemhat if year==2020&ccode==2


*based on V-DEM’s classifications, no democracy has ever failed at a per capita income above about $26,000 (in 2011 US dollars) 
*or after surviving for more than 43 years.
*HERE I USE THE ACTUAL MADDISON DATA, RATHER THAN THE FARISS ESTIMATES, WHICH ARE UNBIASED AND HAVE BROADER COVERAGE, BUT DIFFER SLIGHTLY FROM THE 
*MADDISON ORIGINALS.
use "breakdown cases.dta", clear
xtset ccode year
gsort -gdppc
list country year gdppc if vdemdembkd==1, clean noobs

gsort -vdemdemyrs
list country year vdemdemyrs if vdemdembkd==1, clean noobs

*Ignoring quickly reversed changes, 17 V-DEM autocracies became democracies between 2000 and 2021, while 15 democracies 
*became autocracies... More than two billion people live in the new autocracies, compared to less than 200 million in the new democracies. 
use "breakdown cases.dta", clear
xtset ccode year
replace e_pop = e_pop/100
list country l2.e_pop if l21.v2x_regime<2&v2x_regime>=2&v2x_regime~=.&year==2021
list country l2.e_pop  if l21.v2x_regime>=2&v2x_regime<2&l21.v2x_regime~=.&year==2021

gen x = 0
replace x=1 if l21.v2x_regime<2&v2x_regime>=2&v2x_regime~=.&year==2021
gen xpop = x*l2.e_pop
gen y = 0
replace y=1 if l21.v2x_regime>=2&v2x_regime<2&l21.v2x_regime~=.&year==2021
gen ypop = y*l2.e_pop
bys year: egen uppop = sum(xpop)
bys year: egen downpop = sum(ypop)
list uppop downpop if year==2021&ccode==2

log close
